<ion-header collapsible>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate" />
        </ion-buttons>
        <ion-title>
            <h1>{{ user?.fullname }}</h1>
        </ion-title>
    </ion-toolbar>
</ion-header>
<ion-content [core-swipe-navigation]="users" class="limited-width">
    <ion-refresher slot="fixed" [disabled]="!userLoaded" (ionRefresh)="refreshUser($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}" />
    </ion-refresher>
    <core-loading [hideUntil]="userLoaded">
        <ion-list *ngIf="user && !isDeleted && isEnrolled">
            <ion-item class="core-user-profile-maininfo ion-text-wrap" collapsible>
                <core-user-avatar [user]="user" [userId]="user.id" [linkProfile]="false" [checkOnline]="true" slot="start" />
                <ion-label>
                    <h1>{{ user.fullname }}</h1>
                    <p *ngIf="user.address">
                        <ion-icon name="fas-location-dot" [attr.aria-hidden]="true" /> {{ user.address }}
                    </p>
                    <p *ngIf="rolesFormatted">
                        <strong>{{ 'core.user.roles' | translate}}</strong>{{'core.labelsep' | translate}}
                        {{ rolesFormatted }}
                    </p>
                    <p *ngIf="user.lastaccess !== undefined">
                        <strong>{{ 'core.lastaccess' | translate }}: </strong>
                        <span *ngIf="user.lastaccess">{{ user.lastaccess | coreTimeAgo }}</span>
                        <ng-container *ngIf="!user.lastaccess">{{ 'core.never' | translate }}</ng-container>
                    </p>
                </ion-label>
            </ion-item>

            <div class="core-user-communication-handlers" *ngIf="(buttonHandlers && buttonHandlers.length) || isLoadingHandlers">
                <ion-item *ngIf="buttonHandlers && buttonHandlers.length">
                    <ion-label>
                        <ion-button *ngFor="let handler of buttonHandlers" expand="block" size="default"
                            [ngClass]="['core-user-profile-handler', handler.class || '']" (click)="handlerClicked($event, handler)"
                            [hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [disabled]="handler.spinner">
                            <ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
                            {{ handler.title | translate }}
                        </ion-button>
                    </ion-label>
                </ion-item>
                <div *ngIf="isLoadingHandlers" class="ion-text-center core-loading-handlers">
                    <ion-spinner [attr.aria-label]="'core.loading' | translate" />
                </div>
            </div>
            <ion-item button class="ion-text-wrap core-user-profile-handler" (click)="openUserDetails()"
                [attr.aria-label]="'core.user.details' | translate" [detail]="true">
                <ion-icon name="fas-user" slot="start" aria-hidden="true" />
                <ion-label>
                    <p class="item-heading">{{ 'core.user.details' | translate }}</p>
                </ion-label>
            </ion-item>
            <ion-item class="ion-text-center core-loading-handlers" *ngIf="isLoadingHandlers">
                <ion-label>
                    <ion-spinner [attr.aria-label]="'core.loading' | translate" />
                </ion-label>
            </ion-item>
            <ion-item button *ngFor="let handler of listItemHandlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
                [ngClass]="['core-user-profile-handler', handler.class || '']" [hidden]="handler.hidden"
                [attr.aria-label]="handler.title | translate" [detail]="true">
                <ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
                <ion-label>
                    <p class="item-heading">{{ handler.title | translate }}</p>
                </ion-label>
                <ion-badge slot="end" *ngIf="handler.showBadge" [hidden]="handler.loading || !handler.badge" aria-hidden="true">
                    {{handler.badge}}
                </ion-badge>
                <span *ngIf="handler.showBadge && handler.badge && handler.badgeA11yText" class="sr-only">
                    {{ handler.badgeA11yText | translate: {$a : handler.badge } }}
                </span>
                <ion-spinner slot="end" *ngIf="handler.showBadge && handler.loading" [attr.aria-label]="'core.loading' | translate" />
            </ion-item>
        </ion-list>
        <core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="far-user"
            [message]=" 'core.user.detailsnotavailable' | translate" />
        <core-empty-box *ngIf="isDeleted" icon="far-user" [message]="'core.userdeleted' | translate" />
        <core-empty-box *ngIf="isSuspended" icon="far-user" [message]="'core.usersuspended' | translate" />
        <core-empty-box *ngIf="!isEnrolled" icon="far-user" [message]="'core.notenrolledprofile' | translate" />
    </core-loading>
</ion-content>
